package com.zkx.laolaiyi.listener;

import com.zkx.laolaiyi.constant.MqExchangeConstants;
import com.zkx.laolaiyi.constant.MqQueueConstants;
import com.zkx.laolaiyi.entity.User;
import com.zkx.laolaiyi.service.IUserService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Component
@Slf4j
@RequiredArgsConstructor
public class RegisterListener {
//    private final PasswordEncoder passwordEncoder;
//    private final IUserService userService;
//    @RabbitListener(
//            bindings = @QueueBinding(
//                    value = @Queue(name = MqQueueConstants.REGISTER_QUEUE + 1),
//                    exchange = @Exchange(name = MqExchangeConstants.REGISTER_EXCHANGE_FANOUT)
//            )
//    )
//    public void doRegister(@Payload User user) {
//        log.info("用户：{}正在注册，当前时间为{}\n", user, LocalDateTime.now());
//        user.setPassword(passwordEncoder.encode(user.getPassword()));
//        try {
//            boolean save = userService.save(user);
//        } catch (Exception e) {
//            log.error("用户注册错误：", e);
//        }
//
//    }
}
